<template>
    <div>
        <Card>
            <p slot="title">
                <Icon type="upload"></Icon>
                商户数据上传
            </p>
            <div>
                <Row type="flex" justify="center" align="middle" class="height-100">
                    入库渠道：&nbsp;&nbsp;
                    <Select v-model="channel.channelId" style="width:200px" >
                        <Option v-for="channel in channelList" :value="channel.channelId" :key="channel.channelId">{{ channel.channelName }}</Option>
                    </Select>
                </Row>
            </div>
            <br>
            <div>
                <Row type="flex" justify="center" align="middle" class="height-100">
                    文件类型：&nbsp;&nbsp;
                    <Select v-model="channel.fileType" style="width:200px">
                        <Option v-for="type in fileTypeList" :value="type.key" :key="type.key">{{ type.value }}</Option>
                    </Select>
                </Row>
            </div>
            <br>
            <div>
                <!-- class="height-120px" -->
                <Row type="flex" justify="center" align="middle" class="height-100">
                    <Upload
                        action="//10.7.13.126:8081/organization/exportStore/"
                        :data="{'channelId':channel.channelId ,'fileType':channel.fileType}"
                        :format="['xlsx', 'xls', 'jpg']"
                        :on-format-error="handleFormatError"
                    >
                        <span>入库文件：&nbsp;&nbsp;</span>
                        <Button type="ghost" icon="ios-cloud-upload-outline">上传文件</Button>
                    </Upload>
                </Row>
            </div>
        </Card>
    </div>
</template>
<script>
import organization from '@/api/organization';
import dictionary from '@/api/dictionary';

export default {
    data () {
        return {
            channelList: [],
            fileTypeList: [],
            channel: {
                channelId: '',
                channelName: '',
                fileType: ''
            },
            approve: {
                merchantFileId: '123123',
                approveStatus: '01'
            },
            organizationType: {
                type: 1
            },
            dicData: {
                dicTypeId: 'CDI_FILE_TYPE'
            }

        };
    },
    mounted () {
        this.queryOrganizationByType();
        this.queryFileType();
    },
    methods: {
        handleFormatError (file) {
            this.$Notice.warning({
                title: '文件格式不正确',
                desc: '文件 ' + file.name + ' 格式不正确，请选择图片文件。'
            });
        },
        approveMerchantData () {
            organization.approveMerchantData(this.approve);
        },
        queryOrganizationByType () {
            organization.queryOrganizationByType(this.organizationType).then(result => {
                result.datas.data.bizData.organizations.map(org => {
                    this.channelList.push({
                        channelId: org.channelId,
                        channelName: org.name
                    });
                });
            });
        },
        queryFileType () {
            dictionary.queryDicByType(this.dicData).then(result => {
                result.datas.data.bizData.dictionaryDatas.map(dic => {
                    this.fileTypeList.push({
                        key: dic.key,
                        value: dic.value
                    });
                });
            });
        }
    }
};
</script>

<style>

</style>
